using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
using MBLocale;


public partial class TaskConfig : System.Web.UI.Page
{
    string strPagesetRowID = "aa922f981c2500e0"; // task_config
    string str_Page_Id = "p_task_config";
    string str_hidden_ctrls = "";
    DataSet dsePageInfo = new DataSet();
    DataTable dtaData = new DataTable();
    DataSet dseInputInfo;
    DataRow droPageData;
    DataSet dseTempInputInfo = new DataSet();
    DataRow drpage = null;
    bool IsEdit = false;
    bool IsCopy = false;
    HDDatabase HDD;
    DynamicDisplayI DDI;
    DataTable dt_p_assign_task = new DataTable();
    ArrayList arr_emailInsert = new ArrayList();
    HtmlForm frmObj;
    string strErrMessage = "";
    bool StatusChange = false;

    protected void Page_PreInit(object sender, EventArgs e)
    {
        this.Theme = Session["Theme"].ToString();
        this.Title = "MaxBlox";
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        security hdds = new security();
        if (Session["userid"] == null) Response.Redirect(hdds.SessionExpiryURL);
        if (Session["userid"].ToString() == "") Response.Redirect(hdds.SessionExpiryURL);

        string strErrorMsg = ""; // Added by 'Imran Gani' on 19-Jun-2014, for validate URL
        if (!hdds.IsValidPageURL(ref strErrorMsg))
        {
            lblMessage.Text = wrapItAsMessage(strErrorMsg, true);
            TABLE1.Visible = false;
            return;
        }

        if (Request.QueryString["mn"] != null)
            hdds.logMenuClick(Request.QueryString["mn"].ToString());
        
        if (this.Master.FindControl("Form1") != null)
            frmObj = (HtmlForm)this.Master.FindControl("Form1");
        
        PageInfoLoad PIL = new PageInfoLoad();
        dsePageInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowID);

        HDD = new HDDatabase();

        if (!Page.IsPostBack)
        {
            string ret = MBLocalization.getDateFormat(HttpContext.Current.Session["userlocale"].ToString());
            cal1.Format = ret + " hh:mm tt";
            Cal2.Format = ret + " hh:mm tt";
            LoadDDL();
            loadOwnerid();
            CheckForChangeOwner();
            string strPK = "";
            if (Request.QueryString["PK"] != null)
                strPK = Request.QueryString["PK"].ToString();

            imgsearch2.Attributes.Add("onclick", "javascript:openlookupwindow('p_task_config_owner_id','txt_owner_id','f496930dfe0b690f','" + strPK + "','" + Request.QueryString["pgs_id"].ToString() + "');");
            imgsearch.Attributes.Add("onclick", "javascript:CheckObj();");

            LoadList(LstLeft);
            if (Request.QueryString["ID"] != null && Request.QueryString["ID"] != "")
            {
                if (Request.QueryString["pg"] != null && Request.QueryString["pg"] != "")
                {
                    try
                    {
                        string PageID = Request.QueryString["pg"].ToString();
                        string object_id = HDD.GetColumnValue("select object_id from sy_pg where af_row_id  ='" + PageID + "'");
                        string object_Row_id = HDD.GetColumnValue("select  af_row_id from sy_obj where object_id='" + object_id + "'");
                        if (object_Row_id != "")
                        {
                            object_ref.SelectedValue = object_Row_id;
                            p_task_config_object_record_ref.Value = Request.QueryString["ID"].ToString();
                            LoadObjGrid(object_Row_id);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogWriter.WriteLog("Error : Load Object : " + ex.Message);
                    }
                    finally
                    {
                        HDD = null;
                    }
                }
            }
        }
        else
        {
            // LoadControl();
        }
        if (hih_RTlistvalue.Value != "" && hih_RTlistvalue.Value != "Right" && hih_RTlistvalue.Value != "Left")
        {
            LoadList(LstRight);
            string[] lstrt = hih_RTlistvalue.Value.Split(',');
            if (lstrt.Length > 0)
            {
                if (LstRight.Items.Count > 0)
                {
                    for (int i = LstRight.Items.Count - 1; i >= 0; i--)
                    {
                        int flag = 0;
                        for (int j = 0; j < lstrt.Length; j++)
                        {
                            if (LstRight.Items[i].Value == lstrt[j])
                                flag = 1;
                        }
                        if (flag == 0)
                        {
                            ListItem li = LstRight.Items[i];
                            LstRight.Items.Remove(li);
                        }
                    }
                }
                LoadList(LstLeft);
                if (LstLeft.Items.Count > 0)
                {
                    for (int i = LstLeft.Items.Count - 1; i >= 0; i--)
                    {
                        int flag = 0;
                        for (int j = 0; j < lstrt.Length; j++)
                        {
                            if (LstLeft.Items[i].Value == lstrt[j])
                                flag = 1;
                        }
                        if (flag == 1)
                        {
                            ListItem li = LstLeft.Items[i];
                            LstLeft.Items.Remove(li);
                        }
                    }
                }
            }
        }
        if (hih_RTlistvalue.Value == "Right")
        {
            LoadList(LstRight);
            LstLeft.Items.Clear();
        }
        if (hih_RTlistvalue.Value == "Left")
        {
            LoadList(LstLeft);
            LstRight.Items.Clear();
        }
        if (hih_RTlistvalue.Value == "")
        {
            LstRight.Items.Clear();
            LstLeft.Items.Clear();
            LoadList(LstLeft);
        }

        if (Request.QueryString["PK"] != null)
        {
            IsEdit = true;
            bt_save_next.Visible = false;
            if (!Page.IsPostBack)
                LoadTaskEdit();
            lblHeader.Text = "Task - Edit";
        }

        if (Request.QueryString["CPY"] != null)
        {
            ScreenReader SR = new ScreenReader();
            lblHeader.Text = "Task - Copy";
            IsCopy = true;
            p_task_config_af_row_id.Value = SR.getHashKey();
            p_alert_status_af_row_id.Value = SR.getHashKey();
            p_task_obj_ref_af_row_id.Value = SR.getHashKey();
            SR = null;
        }
        isViewMode();
        if (!Page.IsPostBack)
        {
            getpageicons();
        }
        AddPageToolTip(dsePageInfo.Tables["Page"].Rows[0], ref lblHeader);
        imgsearch1.Attributes.Add("onclick", "javascript:openlookupwindow('p_taskassign_assign_to','assign_to','f496930dfe0b690f','','');hidemultiple();");

    }

    
   
    private void isViewMode()
    {
        if (HttpContext.Current.Request.QueryString["VMODE"] != null)
            if (HttpContext.Current.Request.QueryString["VMODE"] == "1")
            {
                DynamicDisplayI ddi = new DynamicDisplayI();
                HtmlTable ht = (HtmlTable)frmObj.FindControl("ContentPlaceHolder3").FindControl("TABLE1");
                ddi.disableControls(ht);
                ddi = null;
                lblHeader.Text = "Task - View";
                LstLeft.Enabled = true;
                LstRight.Enabled = true;
                //p_task_config_actual_time.Disabled = true;
                //p_task_config_completed.Disabled = true;
                //p_task_config_subject.Disabled = true;
                //p_task_config_est_time.Disabled = true;
                imgsearch.Visible = false;
                imgsearch1.Visible = false;
                imgsearch2.Visible = false;
                bt_save.Visible = false;
                bt_save_next.Visible = false;
                bt_Cancel.Visible = false;
            }
    }

    void LoadTaskEdit()
    {
        DynamicDisplayI ddi = new DynamicDisplayI();
        HDD = new HDDatabase();
        Localization loc = new Localization();
        try
        {
        if (Request.QueryString["PK"] != null)
        {
            string strUTCoffset = "";
            p_task_config_af_row_id.Value = Request.QueryString["PK"].ToString();
            string st_date = "";
            string end_date = "";
            string strTask = "Select * from sy_task_config where af_row_id='" + Request.QueryString["PK"].ToString() + "'";
            DataRow darTaskObj = HDD.GetTableRow(strTask);
            p_task_config_subject.Text = darTaskObj["subject"].ToString();
            p_task_config_desc.Text = darTaskObj["desc"].ToString();

            strUTCoffset = ddi.getUserSetting("sy_usr", "time_zone", "sy_timezone", "utc_offset", "timezone_id");
            #region Old code commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
            // st_date = ddi.getUsersDT(darTaskObj["start_date"].ToString(), strUTCoffset);
           // end_date = ddi.getUsersDT(darTaskObj["finish_date"].ToString(), strUTCoffset);
            //st_date = GetUserTime(darTaskObj["start_date"].ToString(), strUTCoffset, false);
            //end_date = GetUserTime(darTaskObj["finish_date"].ToString(), strUTCoffset, false);
            //System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(HttpContext.Current.Session["userlocale"].ToString());
            #endregion
            st_date = loc.getDateTime4TimeZone(darTaskObj["start_date"].ToString(), strUTCoffset, false, false);
            end_date = loc.getDateTime4TimeZone(darTaskObj["finish_date"].ToString(), strUTCoffset, false, false);
            CultureInfo ci = MBLocalization.getCultureInfo(HttpContext.Current.Session["userlocale"].ToString());
            

            //DateTime dt = Convert.ToDateTime(darTaskObj["start_date"]);
           
            //DateTime currentdate_UTC = System.DateTime.Now.ToUniversalTime();
            //DateTime currentdate_App = System.DateTime.Now;

            //TimeSpan TS = currentdate_App - currentdate_UTC;
            //if (TS.Hours != 0)
            //    dt = dt.AddHours(TS.Hours);
            //if (TS.Minutes != 0)
            //    dt = dt.AddMinutes(TS.Minutes);
            string ret = MBLocalization.getDateFormat(HttpContext.Current.Session["userlocale"].ToString());
            cal1.Format = ret + " hh:mm tt";
            Cal2.Format = ret + " hh:mm tt";
            p_task_config_start_date.Text = st_date.ToString(ci);
            p_task_config_finish_date.Text = end_date.ToString(ci);

            //p_task_config_start_date.Text = dt.ToString(ci);
            //DateTime end_dt = Convert.ToDateTime(darTaskObj["finish_date"]);
            //if (TS.Hours != 0)
            //    end_dt = end_dt.AddHours(TS.Hours);
            //if (TS.Minutes != 0)
            //    end_dt = end_dt.AddMinutes(TS.Minutes);
            //p_task_config_finish_date.Text = end_dt.ToString(ci);
            p_task_config_status.SelectedValue = darTaskObj["status"].ToString();
            // object_ref.SelectedValue = darTaskObj["obj_ref"].ToString();
            p_task_config_priority.SelectedValue = darTaskObj["priority"].ToString();
            //p_task_config_est_time.Text = darTaskObj["est_time"].ToString(); // Commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
            p_task_config_est_time.Text = MBLocalization.getLocalizedDecimal(HttpContext.Current.Session["userlocale"].ToString(), Convert.ToDouble(darTaskObj["est_time"].ToString())); // Added by 'Imran Gani' on 28-Feb-2014, for MBLocale
            p_task_config_est_freq.SelectedValue = darTaskObj["est_freq"].ToString();
            //p_task_config_actual_time.Text = darTaskObj["actual_time"].ToString(); // Commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
            p_task_config_actual_time.Text = MBLocalization.getLocalizedDecimal(HttpContext.Current.Session["userlocale"].ToString(), Convert.ToDouble(darTaskObj["actual_time"].ToString())); // Added by 'Imran Gani' on 28-Feb-2014, for MBLocale
            p_task_config_act_freq.SelectedValue = darTaskObj["act_freq"].ToString();
            //p_task_config_completed.Text = darTaskObj["completed"].ToString(); // Commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
            p_task_config_completed.Text = MBLocalization.getLocalizedDecimal(HttpContext.Current.Session["userlocale"].ToString(), Convert.ToDouble(darTaskObj["completed"].ToString())); // Added by 'Imran Gani' on 28-Feb-2014, for MBLocale
            p_task_config_owner_id.Value = darTaskObj["owner_id"].ToString();


            if (Request.QueryString["PK"] != null)
            {

                LoadEditPage LEP = new LoadEditPage();
                txt_owner_id.Text = LEP.GetUserIDFromAfrowid(darTaskObj["owner_id"].ToString());
                LEP = null;
                if (Request.QueryString["CPY"] != null)
                {
                    //ddownerid.SelectedValue = Session["user_afrowid"].ToString();
                    p_task_config_owner_id.Value = Session["user_afrowid"].ToString();
                    txt_owner_id.Text = Session["userid"].ToString();
                }
            }
            else
            {

                p_task_config_owner_id.Value = Session["user_afrowid"].ToString();
                txt_owner_id.Text = Session["userid"].ToString();

            }
            if (darTaskObj["multi_user"].ToString().ToLower() == "true")
            {

                div_multiple.Style.Add("display", "block");
                AssignToLable.Style.Add("display", "block");
                assign_to.Enabled = false;
                //imgsearch1.Visible = false;
                string str_type = HDD.GetColumnValue("select distinct assign_type from sy_assign_task where task_row_id='" + Request.QueryString["PK"].ToString() + "'");
                DataTable dtAssignTask = HDD.GetDataTable("select distinct assign_type_id from sy_assign_task where task_row_id='" + Request.QueryString["PK"].ToString() + "'");

                p_taskassign_multiple.SelectedValue = str_type;
                LoadList(LstLeft);
                if (dtAssignTask.Rows.Count > 0)
                {
                    if (str_type != "")
                    {
                        if (str_type == "role")
                        {
                            for (int i = 0; i < dtAssignTask.Rows.Count; i++)
                            {
                                for (int j = LstLeft.Items.Count - 1; j >= 0; j--)
                                {
                                    if (LstLeft.Items[j].Value == dtAssignTask.Rows[i]["assign_type_id"].ToString())
                                    {
                                        ListItem li = LstLeft.Items[j];
                                        LstLeft.Items.Remove(li);

                                    }


                                }
                                string str_type_name = HDD.GetColumnValue("select role_name from sy_rol where af_row_id='" + dtAssignTask.Rows[i]["assign_type_id"] + "'");
                                if (dtAssignTask.Rows[i]["assign_type_id"].ToString() != "")
                                {
                                    LstRight.Items.Add(new ListItem(str_type_name, dtAssignTask.Rows[i]["assign_type_id"].ToString()));
                                    hih_RTlistvalue.Value += dtAssignTask.Rows[i]["assign_type_id"].ToString() + ",";

                                }
                            }
                        }
                        if (str_type == "bu")
                        {
                            for (int i = 0; i < dtAssignTask.Rows.Count; i++)
                            {
                                for (int j = LstLeft.Items.Count - 1; j >= 0; j--)
                                {
                                    if (LstLeft.Items[j].Value == dtAssignTask.Rows[i]["assign_type_id"].ToString())
                                    {
                                        ListItem li = LstLeft.Items[j];
                                        LstLeft.Items.Remove(li);

                                    }


                                }
                                string str_type_name = HDD.GetColumnValue("select bu_name from sy_bu where af_row_id='" + dtAssignTask.Rows[i]["assign_type_id"] + "'");
                                if (dtAssignTask.Rows[i]["assign_type_id"].ToString() != "")
                                {
                                    LstRight.Items.Add(new ListItem(str_type_name, dtAssignTask.Rows[i]["assign_type_id"].ToString()));
                                    hih_RTlistvalue.Value += dtAssignTask.Rows[i]["assign_type_id"].ToString() + ",";
                                }
                            }
                        }
                        if (str_type == "usr")
                        {
                            for (int i = 0; i < dtAssignTask.Rows.Count; i++)
                            {
                                for (int j = LstLeft.Items.Count - 1; j >= 0; j--)
                                {
                                    if (LstLeft.Items[j].Value == dtAssignTask.Rows[i]["assign_type_id"].ToString())
                                    {
                                        ListItem li = LstLeft.Items[j];
                                        LstLeft.Items.Remove(li);

                                    }


                                }
                                string str_type_name = HDD.GetColumnValue("select user_id from sy_usr where af_row_id='" + dtAssignTask.Rows[i]["assign_type_id"] + "'");
                                LstRight.Items.Add(new ListItem(str_type_name, dtAssignTask.Rows[i]["assign_type_id"].ToString()));
                                hih_RTlistvalue.Value += dtAssignTask.Rows[i]["assign_type_id"].ToString() + ",";
                            }
                        }

                    }
                    if (hih_RTlistvalue.Value != "")
                        hih_RTlistvalue.Value = hih_RTlistvalue.Value.TrimEnd(',');

                }
            }
            else
            {
                div_multiple.Style.Add("display", "none");
                AssignToLable.Style.Add("display", "none");
                p_taskassign_assign_to.Value = HDD.GetColumnValue("select assign_type_id from sy_assign_task where task_row_id='" + Request.QueryString["PK"].ToString() + "'");
                assign_to.Text = HDD.GetColumnValue("select user_id from sy_usr where af_row_id ='" + p_taskassign_assign_to.Value + "'");


            }

        }
        DataTable dt_obj_rec = HDD.GetDataTable("select * from sy_task_object_ref where task_row_id='" + Request.QueryString["PK"].ToString() + "'");
        p_task_obj_ref_af_row_id.Value = HDD.GetColumnValue("select af_row_id from sy_task_object_ref where task_row_id='" + Request.QueryString["PK"].ToString() + "'");
        if (dt_obj_rec.Rows.Count > 0)
        {
            object_ref.SelectedValue = dt_obj_rec.Rows[0]["obj_ref"].ToString();
            LoadObjGrid(object_ref.SelectedValue);
            p_task_config_object_record_ref.Value = dt_obj_rec.Rows[0]["obj_record_ref"].ToString();
            txt_obj_rec.Text = dt_obj_rec.Rows[0]["obj_record"].ToString();

        }
    }
    catch (Exception ex)
    {
        LogWriter.WriteLog("Error : Retrieving Task  : " + ex.Message);
    }
    finally
    {
        HDD = null;
        loc = null;
        ddi = null;
    }

    }

    #region Page Icon and Tooltip
    private void getpageicons()
    {
        PageIcons icons = new PageIcons();
        HDDatabase Hdd = new HDDatabase();
        try
        {
            string strPagesetRowID = Request.QueryString["pgs_id"].ToString();
            lblHeader.Text = "&nbsp;&nbsp;" + icons.geticontextfrompageset(strPagesetRowID, 2) + "&nbsp;&nbsp;" + lblHeader.Text;
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error :getpageicons() " + ex.Message);
            lblHeader.Text = "<img src=" + PageIcons.strdefaulticon.ToString() + "></img>&nbsp;" + lblHeader.Text;
        }
        finally
        {
            icons = null;
            Hdd = null;
        }
    }

    private void AddPageToolTip(DataRow drpage, ref Label lblHeader)
    {
        if (drpage != null)
        {
            if (!Page.IsPostBack)
                lblHeader.Text = lblHeader.Text + getTootipIcon(drpage);
            Literal lit = new Literal();
            lit.Text = getTooltipContent(drpage);
            td_Page_ToopTip.Controls.Add(lit);
        }
    }

    private string getTootipIcon(DataRow droPage)
    {
        try
        {
            if (!droPage.Table.Columns.Contains("page_desc")) return "";
            if (droPage["page_desc"].ToString().Trim() == "") return "";
            return "&nbsp;<img id=\"page_tooltip_img\" style=\"cursor:pointer;\" src=\"Images/collapse3.gif\" onClick=\"javascript:showHideTooltipDIV();\" border=\"0\"></img>";
        }
        catch (Exception e)
        {
            return "";
        }
    }

    private string getTooltipContent(DataRow droPage)
    {
        if (!droPage.Table.Columns.Contains("page_desc")) return "";
        if (droPage["page_desc"].ToString().Trim() == "") return "";
        return getContent(HttpContext.Current.Server.MapPath("") + @"\scripts\pagetooltipcontent.txt").Replace("<<content>>", CommonFunctions.SafeEncode(droPage["page_desc"].ToString()));
    }

    private string getContent(string fileName)
    {
        try
        {
            if (!File.Exists(fileName))
                return "";
            string temp = "";
            StreamReader sr = new StreamReader(fileName);
            temp = sr.ReadToEnd();
            sr.Close();
            sr = null;
            return temp;
        }
        catch (Exception e)
        {
            return "";
        }
    }

    private string wrapItAsMessage(string msg, bool isError)
    {
        return "<div class=\"" + (isError == true ? "mbErrorMessage" : "mbMessage") + "\">" + msg + "</div>";
    }
    #endregion

    private void LoadList(ListBox list)
    {
        BindControl BC = new BindControl();
        HDDatabase Hdd = new HDDatabase();
        DataTable dt = new DataTable();
        string sql = "";

        if (p_taskassign_multiple.SelectedValue.ToLower() == "usr")
            sql = BC.GetBindSql("92919057f8346696");
        else if (p_taskassign_multiple.SelectedValue.ToLower() == "role")
            sql = BC.GetBindSql("e0b5144eca48948a");
        else if (p_taskassign_multiple.SelectedValue.ToLower() == "bu")
            sql = BC.GetBindSql("dc80380fe3a93228");
        dt.Clear();
        if (sql.Trim() != "")
            dt = Hdd.GetDataTable(sql);
        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {

                list.DataSource = dt;
                list.DataTextField = "Fld";
                list.DataValueField = "Val";
                list.DataBind();

            }
        }
        else
            list.Items.Clear();
        BC = null;
        Hdd = null;

    }

    private void loadOwnerid()
    {
        try
        {
            if (Request.QueryString["PK"] == null)
            {
                //ddownerid.SelectedValue = Session["user_afrowid"].ToString();
                p_task_config_owner_id.Value = Session["user_afrowid"].ToString();
                txt_owner_id.Text = Session["userid"].ToString();
            }
            if (Request.QueryString["PK"] != null)
            {
                if (Request.QueryString["CPY"] != null)
                {
                    //ddownerid.SelectedValue = Session["user_afrowid"].ToString();
                    p_task_config_owner_id.Value = Session["user_afrowid"].ToString();
                    txt_owner_id.Text = Session["userid"].ToString();
                }

            }

        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : loadOwnerid :" + ex.Message);
        }

    }

    private void CheckForChangeOwner()  // Added by srivatsan to Check if user can change owner
    {
        try
        {
            security sec = new security();
            bool status = false;
            status = sec.getRightsForMRUObjects(HttpContext.Current.Request.QueryString["pgs_id"].ToString(), "change_owner");
            if (status == false)
            {

                txt_owner_id.Enabled = false;
                imgsearch2.Visible = false;
            }

            sec = null;
        }
        catch
        {

        }
    }


    private void LoadDDL()
    {
        BindControl BC = new BindControl();
        HDDatabase Hdd = new HDDatabase();
        DataTable dt = new DataTable();
        string sql = "";

        sql = BC.GetBindSql("39a618457d4e579b");
        if (sql.Trim() != "")
            dt = Hdd.GetDataTable(sql);
        p_task_config_status.DataSource = dt;
        p_task_config_status.DataTextField = "Fld";
        p_task_config_status.DataValueField = "Val";
        p_task_config_status.DataBind();
        p_task_config_status.Items.Insert(0, new ListItem("--Select--", ""));
        p_task_config_status.SelectedValue = "NS";

        sql = "";
        dt.Clear();
        sql = BC.GetBindSql("7c3a78a1119224bb");
        if (sql.Trim() != "")
            dt = Hdd.GetDataTable(sql);
        p_task_config_priority.DataSource = dt;
        p_task_config_priority.DataTextField = "Fld";
        p_task_config_priority.DataValueField = "Val";
        p_task_config_priority.DataBind();
        p_task_config_priority.Items.Insert(0, new ListItem("--Select--", ""));
        p_task_config_priority.SelectedValue = "LO";
       
        sql = "";
        dt.Clear();
        sql = BC.GetBindSql("f515b80731a82d6b");
        if (sql.Trim() != "")
            dt = Hdd.GetDataTable(sql);
        p_taskassign_multiple.DataSource = dt;
        p_taskassign_multiple.DataTextField = "Fld";
        p_taskassign_multiple.DataValueField = "Val";
        p_taskassign_multiple.DataBind();
        p_taskassign_multiple.Items.Insert(0, new ListItem("--Select--", "0"));

        sql = "";
        dt.Clear();
        sql = BC.GetBindSql("409066e51afcfd2b");
        if (sql.Trim() != "")
            dt = Hdd.GetDataTable(sql);
        p_task_config_act_freq.DataSource = dt;
        p_task_config_act_freq.DataTextField = "Fld";
        p_task_config_act_freq.DataValueField = "Val";
        p_task_config_act_freq.DataBind();
        p_task_config_act_freq.Items.Insert(0, new ListItem("--Select--", ""));
        p_task_config_act_freq.SelectedValue = "day";

        sql = "";
        dt.Clear();
        sql = BC.GetBindSql("409066e51afcfd2b");
        if (sql.Trim() != "")
            dt = Hdd.GetDataTable(sql);
        p_task_config_est_freq.DataSource = dt;
        p_task_config_est_freq.DataTextField = "Fld";
        p_task_config_est_freq.DataValueField = "Val";
        p_task_config_est_freq.DataBind();
        p_task_config_est_freq.Items.Insert(0, new ListItem("--Select--", ""));
        p_task_config_est_freq.SelectedValue = "day";


        sql = "";
        dt.Clear();
        sql = "Select sy_obj.af_row_id as Val,sy_obj.[object_name] as Fld from sy_obj inner join sy_pgs_mem on sy_obj.object_id = sy_pgs_mem.object_id and sy_obj.associate_task=1";

        dt = Hdd.GetDataTable(sql);
        if (dt.Rows.Count > 0)
        {
            object_ref.DataSource = dt;
            object_ref.DataTextField = "Fld";
            object_ref.DataValueField = "Val";
            object_ref.DataBind();
            object_ref.Items.Insert(0, new ListItem("--Select--", "0"));
        }

        BC = null;
        Hdd = null;
    }








    protected void bt_save_Click(object sender, EventArgs e)
    {
        if (!validateOwnerid(ref lblMessage))
        {
            return;
        }
        bool status = true;
         DynamicDisplayI ddi = new DynamicDisplayI();
        Localization loc = new Localization();
        string start_dt = "";
        string end_dt = "";
        string strUTCoffset = "";
        strUTCoffset = ddi.getUserSetting("sy_usr", "time_zone", "sy_timezone", "utc_offset", "timezone_id");
        //start_dt = GetUserTime(p_task_config_start_date.Text, strUTCoffset,true); // Commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
        //end_dt = GetUserTime(p_task_config_finish_date.Text, strUTCoffset,true); // Commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
        start_dt = loc.getDateTime4TimeZone(p_task_config_start_date.Text, strUTCoffset, true, false);
        end_dt = loc.getDateTime4TimeZone(p_task_config_finish_date.Text, strUTCoffset, true, false);
        if (start_dt != "" && end_dt != "")
        {
            if (IsEdit == false)
            {
                if(!DateValidation(start_dt, end_dt, ref lblMessage))
                    return;
                status = GetTaskData(ref lblMessage);
                if (status == true)
                {
                    if (SaveTask(ref lblMessage))
                    {
                        lblMessage.Text = ErrMessage("&nbsp;<img src='Images/info.gif' border='0'>&nbsp;Data Inserted Successfully", false);
                        ViewState["dseTempInputInfo"] = null;
                        Response.Redirect("DisplayGrid.aspx?mn=" + HDD.GetColumnValue("sy_mnu", "af_row_id", "pageset_id = 'aa922f981c2500e0' and pageset_url = 'TaskConfig.aspx'") + "&pgs_id=aa922f981c2500e0"); // pageset_id and pgs_id = 'task_config'
                    }
                    else
                    {
                        lblMessage.Text = ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Data Insert not successful. " + ErrorMessage, true);
                    }
                }
                else
                {
                    return;

                }

            }
            else
            {
                if (!DateValidation(start_dt, end_dt, ref lblMessage))
                    return;
                status = GetTaskData(ref lblMessage);
                if (status == true)
                {
                    if (SaveTask(ref lblMessage))
                    {

                        lblMessage.Text = ErrMessage("&nbsp;<img src='Images/info.gif' border='0'>&nbsp;Data Inserted Successfully", false);
                        ViewState["dseTempInputInfo"] = null;
                        Response.Redirect("DisplayGrid.aspx?mn=" + HDD.GetColumnValue("sy_mnu", "af_row_id", "pageset_id = 'aa922f981c2500e0' and pageset_url = 'TaskConfig.aspx'") + "&pgs_id=aa922f981c2500e0"); // pageset_id and pgs_id = 'task_config'
                    }
                    else
                    {
                        lblMessage.Text = ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Data Insert not successful. " + ErrorMessage, true);
                    }
                }
                else
                {
                    // lblMessage.Text = ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Invalid Object Data " + ErrorMessage, true);
                    return;
                }
            }
        }
        else
        {
            lblMessage.Text = ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Invalid date  " + ErrorMessage, true);
            return;
        }
        
    }
    private string ErrMessage(string msg, bool isError)
    {
        return "<div class=\"" + (isError == true ? "mbErrorMessage" : "mbMessage") + "\">" + msg + "</div>";
    }
    public string ErrorMessage
    {
        get
        {
            return this.strErrMessage;
        }
    }



    public bool GetTaskData(ref Label lblMessage)
    {
        bool blnStatus = true;

        HDD = new HDDatabase();
        DDI = new DynamicDisplayI();
        DataSet dseInputInfo = new DataSet();

        string[,] pagearr = pagearr = new string[,] 
            {
                {"Task", "aa922f981c2500e0"}, // task_config
                {"Assign", "e5aa35559467834V"}, // assign_task
              //  {"AlertStatus", "alert_status"},
                {"ObjectRec","7e5233c8f1b9a08e"} // task_object_ref
            };

        string strPagesetRowID = "";
        string strPageId = "";
        ScreenReader SR = new ScreenReader();
        Master MA = new Master();
        PageInfoLoad PIL = new PageInfoLoad();
        if (!validateOwnerid(ref lblMessage))
        {
            return false;
        }
        try
        {

            for (int p = 0; p <= pagearr.GetUpperBound(0); p++)
            {
                strPagesetRowID = pagearr[p, 1].ToString();

                

                dsePageInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowID);

                DataTable dtaPageSet = dsePageInfo.Tables["PageSet"];
                DataTable dtaPage = dsePageInfo.Tables["Page"];
                DataTable dtaPageKeys = dsePageInfo.Tables["PageKeys"];
                DataTable dtaPageCtrl = dsePageInfo.Tables["PageCtrl"];

                if (dseTempInputInfo.Tables.Contains(dtaPage.Rows[0]["page_id"].ToString()) == false)
                    SR.CreatePageDataTable(dseTempInputInfo, dtaPage, dtaPageCtrl);

                for (int i = 0; i < dtaPage.Rows.Count; i++)
                {
                    strPageId = dtaPage.Rows[i]["page_id"].ToString();

                    if (strPageId == "p_task_config")
                    {
                        dseTempInputInfo.Tables[strPageId].Clear();
                        droPageData = dseTempInputInfo.Tables[strPageId].NewRow();

                        droPageData["af_row_id"] = p_task_config_af_row_id.Value == "" ? SR.getHashKey() : p_task_config_af_row_id.Value;
                        p_task_config_af_row_id.Value = droPageData["af_row_id"].ToString();
                        if (p_task_config_subject.Text != "")
                        {
                            p_task_config_subject.Text = p_task_config_subject.Text.Replace("<", "").Replace(">", "").Replace("</", "");
                            droPageData["subject"] = p_task_config_subject.Text;
                        }

                        else

                            droPageData["subject"] = "";

                        DynamicDisplayI ddi = new DynamicDisplayI();
                        Localization loc = new Localization();
                        string start_dt = "";
                        string end_dt = "";
                        string strUTCoffset = "";
                        strUTCoffset = ddi.getUserSetting("sy_usr", "time_zone", "sy_timezone", "utc_offset", "timezone_id");
                        //start_dt = GetUserTime(p_task_config_start_date.Text, strUTCoffset,true); // Commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
                        //end_dt = GetUserTime(p_task_config_finish_date.Text, strUTCoffset,true); // Commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
                        start_dt = loc.getDateTime4TimeZone(p_task_config_start_date.Text, strUTCoffset, true, false);
                        end_dt = loc.getDateTime4TimeZone(p_task_config_finish_date.Text, strUTCoffset, true, false);
                        System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(HttpContext.Current.Session["userlocale"].ToString());
                        droPageData["start_date"] = start_dt.ToString(ci);
                        droPageData["finish_date"] = end_dt.ToString(ci);
                        //DateTime start_dt;
                        //DateTime end_dt;
                        //string strUTCoffset = "";
                       
                        //System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(HttpContext.Current.Session["userlocale"].ToString());
                        //droPageData["start_date"] = Convert.ToDateTime(p_task_config_start_date.Text,ci).ToUniversalTime();
                        //droPageData["finish_date"] = Convert.ToDateTime(p_task_config_finish_date.Text,ci).ToUniversalTime(); 
                        if (p_task_config_est_time.Text != "")
                            droPageData["est_time"] = MBLocalization.getNumericValue(HttpContext.Current.Session["userlocale"].ToString(), p_task_config_est_time.Text).ToString();
                        //droPageData["est_time"] = Convert.ToDouble(p_task_config_est_time.Text); // Commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
                        else
                            droPageData["est_time"] = 0;
                        if (p_task_config_actual_time.Text != "")
                            droPageData["actual_time"] = MBLocalization.getNumericValue(HttpContext.Current.Session["userlocale"].ToString(), p_task_config_actual_time.Text).ToString();
                        //droPageData["actual_time"] = Convert.ToDouble(p_task_config_actual_time.Text); // Commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
                        else
                            droPageData["actual_time"] = 0;

                        droPageData["priority"] = p_task_config_priority.Text;
                        if (p_task_config_desc.Text != "")
                            droPageData["desc"] = p_task_config_desc.Text;
                        else
                            droPageData["desc"] = "";

                        droPageData["is_active"] = true;
                        if (p_task_config_completed.Text != "")
                            droPageData["completed"] = MBLocalization.getNumericValue(HttpContext.Current.Session["userlocale"].ToString(), p_task_config_completed.Text).ToString();
                        //droPageData["completed"] = Convert.ToDouble(p_task_config_completed.Text); // Commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
                        else
                            droPageData["completed"] = 0;

                        droPageData["est_freq"] = p_task_config_est_freq.Text;
                        droPageData["act_freq"] = p_task_config_act_freq.Text;
                        droPageData["status"] = p_task_config_status.Text;
                        droPageData["owner_id"] = p_task_config_owner_id.Value;
                        if (p_taskassign_multiple.SelectedIndex == 0)
                        {
                            droPageData["multi_user"] = false;

                        }
                        else
                            droPageData["multi_user"] = true;

                        dseTempInputInfo.Tables[strPageId].Rows.Add(droPageData);

                    }
                    else if (strPageId == "p_assign_task")
                    {
                        dseTempInputInfo.Tables[strPageId].Clear();
                        string value = "";
                        int int_rowcnt = LstRight.Items.Count;

                        if (p_taskassign_multiple.SelectedIndex != 0 & LstRight.Items.Count > 0)
                        {


                            for (int int_rows = 0; int_rows < int_rowcnt; int_rows++)
                            {

                                //if (p_taskassign_multiple.Text == "role")
                                //{

                                //   // DataTable dt = HDD.GetDataTable("SELECT * from sy_usr_rol where role_id='" + LstRight.Items[int_rows].Value + "'");
                                //    if (LstRight.Items.Count > 0)
                                //    {
                                //        for (int j = 0; j < LstRight.Items.Count; j++)
                                //        {
                                            droPageData = dseTempInputInfo.Tables[strPageId].NewRow();

                                            droPageData["af_row_id"] = p_assign_task_af_row_id.Value == "" ? SR.getHashKey() : p_assign_task_af_row_id.Value;
                                            droPageData["task_row_id"] = p_task_config_af_row_id.Value;
                                            droPageData["assign_type"] = p_taskassign_multiple.Text;
                                            droPageData["assign_type_id"] = LstRight.Items[int_rows].Value;
                                            //droPageData["assign_to"] = dt.Rows[j]["user_id"].ToString();
                                            droPageData["owner_id"] = p_task_config_owner_id.Value;

                                            dseTempInputInfo.Tables[strPageId].Rows.Add(droPageData);
                                //        }
                                //    }
                                //    //else if (dt.Rows.Count <= 0)
                                //    //{
                                //    //    AddnewRow(dt, LstRight.Items[int_rows].Value, strPageId, p_taskassign_multiple.Text);
                                //    //}
                                //}

                                //else if (p_taskassign_multiple.Text == "bu")
                                //{

                                //    //DataTable dt = HDD.GetDataTable("SELECT * from sy_usr where bu_id='" + LstRight.Items[int_rows].Value + "'");
                                //    //AssignTask(dt, LstRight.Items[int_rows].Value, strPageId, p_taskassign_multiple.Text);
                                //    if (LstRight.Items.Count > 0)
                                //    {
                                //        for (int j = 0; j < LstRight.Items.Count; j++)
                                //        {
                                //            droPageData = dseTempInputInfo.Tables[strPageId].NewRow();

                                //            droPageData["af_row_id"] = p_assign_task_af_row_id.Value == "" ? SR.getHashKey() : p_assign_task_af_row_id.Value;
                                //            droPageData["task_row_id"] = p_task_config_af_row_id.Value;
                                //            droPageData["assign_type"] = p_taskassign_multiple.Text;
                                //            droPageData["assign_type_id"] = LstRight.Items[int_rows].Value;
                                //            //droPageData["assign_to"] = dt.Rows[j]["af_row_id"].ToString();
                                //            droPageData["owner_id"] = p_task_config_owner_id.Value;

                                //            dseTempInputInfo.Tables[strPageId].Rows.Add(droPageData);
                                //        }
                                //    }
                                    //else if (dt.Rows.Count <= 0)
                                    //{
                                    //    AddnewRow(dt, LstRight.Items[int_rows].Value, strPageId, p_taskassign_multiple.Text);

                                //   }
                                //}
                                //else if (p_taskassign_multiple.Text == "usr")
                                //{

                                //    droPageData = dseTempInputInfo.Tables[strPageId].NewRow();
                                //    droPageData["af_row_id"] = p_assign_task_af_row_id.Value == "" ? SR.getHashKey() : p_assign_task_af_row_id.Value;
                                //    droPageData["task_row_id"] = p_task_config_af_row_id.Value;
                                //    droPageData["assign_type"] = p_taskassign_multiple.Text;
                                //    droPageData["assign_type_id"] = LstRight.Items[int_rows].Value;
                                //    //droPageData["assign_to"] = LstRight.Items[int_rows].Value;
                                //    droPageData["owner_id"] = p_task_config_owner_id.Value;

                                //    dseTempInputInfo.Tables[strPageId].Rows.Add(droPageData);
                                //}
                            }
                        }
                        else if (p_taskassign_multiple.SelectedIndex == 0 )
                        {
                            droPageData = dseTempInputInfo.Tables[strPageId].NewRow();
                            droPageData["af_row_id"] = p_assign_task_af_row_id.Value == "" ? SR.getHashKey() : p_assign_task_af_row_id.Value;
                            droPageData["task_row_id"] = p_task_config_af_row_id.Value;
                            droPageData["assign_type"] = "usr";
                            BindControl BC = new BindControl();
                            if (assign_to.Text != "")
                            {
                                string sql = BC.GetBindSql("f496930dfe0b690f");
                                DataSet dsBind = HDD.GetDataset(sql);
                                DataRow[] drrbind = null;

                                try
                                {
                                    drrbind = dsBind.Tables[0].Select("fld = '" + assign_to.Text + "'");
                                }
                                catch
                                {
                                    blnStatus = false;
                                    lblMessage.Text = ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Invalid User Data " + ErrorMessage, true);
                                    // errormessage = "Invalid data for " + droPageCtrl["control_name"].ToString() + ": " + data + "";
                                }
                                if (drrbind != null)
                                {
                                    if (drrbind.Length != 0)
                                    {
                                        p_taskassign_assign_to.Value = drrbind[0]["val"].ToString();

                                        droPageData["assign_type_id"] = drrbind[0]["val"].ToString();
                                    }
                                    else
                                    {
                                        blnStatus = false;
                                        lblMessage.Text = ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Invalid User Data " + ErrorMessage, true);
                                    }
                                }
                                else
                                {
                                    blnStatus = false;
                                    lblMessage.Text = ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Invalid User Data " + ErrorMessage, true);
                                }


                            }

                            droPageData["owner_id"] = p_task_config_owner_id.Value;

                            dseTempInputInfo.Tables[strPageId].Rows.Add(droPageData);


                        }

                    }
                    else if (strPageId == "p_task_object_ref")
                    {
                        #region Old code commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
                        //dseTempInputInfo.Tables[strPageId].Clear();
                        //droPageData = dseTempInputInfo.Tables[strPageId].NewRow();
                        //droPageData["af_row_id"] = p_task_obj_ref_af_row_id.Value == "" ? SR.getHashKey() : p_task_obj_ref_af_row_id.Value;
                        //droPageData["task_row_id"] = p_task_config_af_row_id.Value;
                        //droPageData["obj_ref"] = object_ref.SelectedValue;
                        //string table_name = HDD.GetColumnValue("Select object_table from sy_obj where af_row_id='" + object_ref.SelectedValue + "'");
                        //DataSet dsobj = HDD.GetDataset("Select * from " + table_name);
                        //DataRow drrobj = null;
                        //try
                        //{
                        //    for (int s = 0; s < dsobj.Tables[0].Rows.Count; s++)
                        //    {
                        //        for (int j = 0; j < dsobj.Tables[0].Columns.Count; j++)
                        //        {
                        //            if (dsobj.Tables[0].Rows[s][j].ToString() == txt_obj_rec.Text)
                        //            {
                        //                drrobj = dsobj.Tables[0].Rows[s];
                        //            }
                        //        }
                        //    }
                        //}
                        #endregion
                        #region New code Added by 'Imran Gani' on 28-Feb-2014, to use switch case with MBLocale
                        DataRow drrobj = null;
                        try
                        {
                            dseTempInputInfo.Tables[strPageId].Clear();
                            droPageData = dseTempInputInfo.Tables[strPageId].NewRow();
                            droPageData["af_row_id"] = p_task_obj_ref_af_row_id.Value == "" ? SR.getHashKey() : p_task_obj_ref_af_row_id.Value;
                            droPageData["task_row_id"] = p_task_config_af_row_id.Value;
                            droPageData["obj_ref"] = object_ref.SelectedValue;
                            string table_name = HDD.GetColumnValue("Select object_table from sy_obj where af_row_id='" + object_ref.SelectedValue + "'");
                            string SearchField = HDD.GetColumnValue("select top 1 search_attrib_id from sy_pgs_srh where pageset_id = (select pageset_id from sy_pgs_mem where object_id = (select object_id from sy_obj where af_row_id = '" + object_ref.SelectedValue + "')) order by search_seq;");
                            string sFieldDataType = HDD.GetColumnValue("select attrib_data_type from sy_obj_att where object_id = '" + object_ref.SelectedValue + "' and attrib_id = '" + SearchField + "';");
                            string sVal = "";
                            Localization loc = new Localization(); // Added by 'Imran Gani' on 06-Mar-2014, for MBLocale
                            sVal = loc.getDBValueFromLocale(txt_obj_rec.Text.Trim(), sFieldDataType);
                            loc = null;
                            drrobj = HDD.GetTableRow("Select * from " + table_name + " where " + SearchField + " = '" + sVal.Replace("'", "''") + "';");
                        }
                        #endregion
                        catch
                        {
                            blnStatus = false;
                            lblMessage.Text = ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Invalid Object Data " + ErrorMessage, true);
                            // errormessage = "Invalid data for " + droPageCtrl["control_name"].ToString() + ": " + data + "";
                        }
                        if (drrobj != null)
                        {

                            p_task_config_object_record_ref.Value = drrobj["af_row_id"].ToString();

                            droPageData["obj_record_ref"] = drrobj["af_row_id"].ToString();
                            droPageData["obj_record"] = txt_obj_rec.Text;

                        }
                        else
                        {
                            blnStatus = false;
                            lblMessage.Text = ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Invalid Object Data " + ErrorMessage, true);
                        }

                        droPageData["owner_id"] = p_task_config_owner_id.Value;
                        dseTempInputInfo.Tables[strPageId].Rows.Add(droPageData);
                    }


                }
            }
            if ((IsEdit) && (!IsCopy))
            {
                if (Request.QueryString["PK"] != null)
                {
                    dt_p_assign_task = dseTempInputInfo.Tables["p_assign_task"].Copy();
                    dseTempInputInfo.Tables["p_assign_task"].Rows.Clear();
                }
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error :Getdataset in Task()" + ex.Message);
            
        }
        finally
        {
            SR = null;
            MA = null;
            PIL = null;
            DDI = null;
            HDD = null;
        }
       
        ViewState["dseTempInputInfo"] = dseTempInputInfo;
        return blnStatus;
    }

    void AddnewRow(DataTable dt, string Value, string strPageId, string AssignType)
    {
        ScreenReader SR = new ScreenReader();
        if (dt.Rows.Count <= 0)
        {
            droPageData = dseTempInputInfo.Tables[strPageId].NewRow();

            droPageData["af_row_id"] = p_assign_task_af_row_id.Value == "" ? SR.getHashKey() : p_assign_task_af_row_id.Value;
            droPageData["task_row_id"] = p_task_config_af_row_id.Value;
            droPageData["assign_type"] = AssignType;
            droPageData["assign_type_id"] = Value;
            droPageData["assign_to"] = "";
            droPageData["owner_id"] = p_task_config_owner_id.Value;

            dseTempInputInfo.Tables[strPageId].Rows.Add(droPageData);
            SR = null;

        }

    }

    bool DeleteAndInsertAssignTask()
    {
        SqlCommand sqlcmd;
        ArrayList arrSqlCmd = new ArrayList();

        bool status = true;
        if (Request.QueryString["PK"] != null)
        {
            DataTable dt = HDD.GetDataTable("select * from sy_assign_task where task_row_id ='" + Request.QueryString["PK"].ToString() + "'");
            if (dt.Rows.Count > 0)
            {
                string delete = "delete from sy_assign_task where task_row_id ='" + Request.QueryString["PK"].ToString() + "'";
                sqlcmd = new SqlCommand(delete);
                arrSqlCmd.Add(sqlcmd);


            }

        }
        if (dt_p_assign_task.Rows.Count > 0)
        {
            for (int i = 0; i < dt_p_assign_task.Rows.Count; i++)
            {
                ScreenReader SR = new ScreenReader();
                string strinsert = " INSERT into sy_assign_task (af_row_id,task_row_id,assign_type,assign_to,assign_type_id,created_by,created_at,modified_at,modified_by,owner_id) values (@af_row_id,@task_row_id,@assign_type,@assign_to,@assign_type_id,@created_by,@created_at,@modified_at,@modified_by,@owner_id)";
                sqlcmd = new SqlCommand(strinsert);
                sqlcmd.Parameters.Add("@af_row_id", System.Data.SqlDbType.NVarChar).Value = p_assign_task_af_row_id.Value == "" ? SR.getHashKey() : p_assign_task_af_row_id.Value;
                sqlcmd.Parameters.Add("@task_row_id", System.Data.SqlDbType.NVarChar).Value = dt_p_assign_task.Rows[i]["task_row_id"];
                sqlcmd.Parameters.Add("@assign_type", System.Data.SqlDbType.NVarChar).Value = dt_p_assign_task.Rows[i]["assign_type"];
                sqlcmd.Parameters.Add("@assign_type_id", System.Data.SqlDbType.NVarChar).Value = dt_p_assign_task.Rows[i]["assign_type_id"];
                sqlcmd.Parameters.Add("@assign_to", System.Data.SqlDbType.NVarChar).Value = dt_p_assign_task.Rows[i]["assign_to"];
                sqlcmd.Parameters.Add("@created_by", System.Data.SqlDbType.NVarChar).Value = p_task_config_owner_id.Value;
                sqlcmd.Parameters.Add("@modified_by", System.Data.SqlDbType.NVarChar).Value = p_task_config_owner_id.Value;
                sqlcmd.Parameters.Add("@created_at", System.Data.SqlDbType.DateTime).Value = DateTime.Now.ToString();
                sqlcmd.Parameters.Add("@modified_at", System.Data.SqlDbType.DateTime).Value = DateTime.Now.ToString();
                sqlcmd.Parameters.Add("@owner_id", System.Data.SqlDbType.NVarChar).Value = p_task_config_owner_id.Value;
                arrSqlCmd.Add(sqlcmd);
            }
        }


        if (!this.HDD.ExecuteTransaction(arrSqlCmd))
        {
            lblMessage.Text = ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Assign Task Insert not successful. " + ErrorMessage, true);
            status = false;
        }
        return status;


    }


    public bool SaveTask(ref Label lblMessage)
    {
        security hdds = new security();
        bool CanCreate = true;
        CanCreate = hdds.getObjectRightsForUser("ob_task_config", "read");
        

        if (!validateOwnerid(ref lblMessage))
        {
            return false;
        }
        bool blnStatus = true;
        if (CanCreate==true)
        {
        DataSet dsetempInfo;
        Master MA = new Master();

        string strPagesetRowID = "";

        string[,] pagearr = pagearr = new string[,] 
            {
                 {"Task", "aa922f981c2500e0"}, // task_config
                {"Assign", "e5aa35559467834V"}, // assign_task
               // {"AlertStatus", "alert_status"},
                {"ObjectRec","7e5233c8f1b9a08e"} // task_object_ref
            };
        PageInfoLoad PIL = new PageInfoLoad();
        dsePageInfo = new DataSet();
        dseInputInfo = new DataSet();

        dsePageInfo = PIL.GetPageSetPageCtrlInfo("aa922f981c2500e0"); // task_config

        for (int j = 1; j <= pagearr.GetUpperBound(0); j++)
        {
            dsetempInfo = new DataSet();
            strPagesetRowID = pagearr[j, 1].ToString();
            dsetempInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowID);
            dsePageInfo.Tables["Page"].Merge(dsetempInfo.Tables["Page"]);
            dsePageInfo.Tables["PageCtrl"].Merge(dsetempInfo.Tables["PageCtrl"]);
            dsePageInfo.Tables["PageKeys"].Merge(dsetempInfo.Tables["PageKeys"]);
        }

        dseInputInfo.Merge(dseTempInputInfo, true);
        HDDatabase HDD = new HDDatabase();
        DefaultColumnUpdate();
        try
        {

            if ((IsEdit) && (!IsCopy))
            {


                blnStatus = MA.ProcessOperation(dsePageInfo, dseInputInfo, "UPDATE");
                if (blnStatus)
                {
                    blnStatus = DeleteAndInsertAssignTask();
                    // DataTable dt_taskAlert = HDD.GetDataTable("select * from sy_acr_mem where acr_id=(select af_row_id from sy_acr where acr_id='1008')");

                    string emailAlert = HDD.GetColumnValue("select mem_id  from sy_acr_mem where acr_id=(select af_row_id from sy_acr where acr_id='1008') and mem_name='e-mailAlert'");
                    if (emailAlert == "1")
                    {
                        sendEmailupdate();
                        //if (StatusChange == true)
                        //{
                        //    string status = "Change of Status";
                        //    sendEmailAlert(status);
                        //}
                    }
                }


            }
            else
            {
                string subject = "New Task Allocated";
                blnStatus = MA.ProcessOperation(dsePageInfo, dseInputInfo, "INSERT");
                string emailAlert = HDD.GetColumnValue("select mem_id  from sy_acr_mem where acr_id=(select af_row_id from sy_acr where acr_id='1008') and mem_name='e-mailAlert'");
                if (emailAlert == "1")
                {
                    sendEmailAlert(subject);
                }
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error :Saving E-mail updates in Task" + ex.Message);
            
        }
        finally
        {
            HDD = null;
        }
        this.strErrMessage = MA.ErrorMessage;
    }
    else
    {
        lblMessage.Text = ErrMessage("<img src=\"Images/info.gif\" alt=\"\"></img>&nbsp;You do not have sufficient access permission.", true);
        blnStatus = false;
    }

        return blnStatus;

    }
    private bool sendEmailupdate()
    {
        HDDatabase HDD = new HDDatabase();
        string subject = "Task Status";
        

        bool status = true;
        status = sendEmailAlert(subject);
        //bool exist = false;
        //arr_emailInsert.Clear();
        //DataTable Dt_email = HDD.GetDataTable("select * from sy_emails where related_to='" + p_task_config_af_row_id.Value + "'");
        //if (dt_p_assign_task.Rows.Count > 0)
        //{
        //    for (int i = 0; i < dt_p_assign_task.Rows.Count; i++)
        //    {
        //        for (int j = 0; j < Dt_email.Rows.Count; j++)
        //        {
        //            string user_email = HDD.GetColumnValue("select email_id from sy_usr where af_row_id='" + dt_p_assign_task.Rows[i]["assign_to"].ToString() + "'");
        //            if (user_email == Dt_email.Rows[j]["to_address"].ToString())
        //            {
        //                exist = true;
        //            }
        //        }
        //        if (exist == false)
        //        {
        //            InsertEmailRecord(dt_p_assign_task.Rows[i]["assign_to"].ToString(), subject);
        //        }
        //    }
        //}
        //if (!this.HDD.ExecuteTransaction(arr_emailInsert))
        //{
        //    lblMessage.Text = ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "E-mail Insert not successful. " + ErrorMessage, true);
        //    status = false;
        //}
        return status;

    }

    private bool sendEmailAlert(string subject)
    {

        HDDatabase HDD = new HDDatabase();


        bool status = true;
        try
        {

        if (dseInputInfo.Tables["p_assign_task"] != null & dseInputInfo.Tables["p_assign_task"].Rows.Count > 0)
        {
            GetUsers(dseInputInfo.Tables["p_assign_task"], subject);


        }
        if (IsEdit)
        {
            if (dt_p_assign_task != null & dt_p_assign_task.Rows.Count > 0)
            {

                GetUsers(dt_p_assign_task, subject);
                //InsertEmailRecord(dt_p_assign_task.Rows[i]["assign_to"].ToString(), subject);



            }

        }
        string modelConString = "";

        modelConString = Session["servercon"].ToString();

        SqlConnection conObj = new SqlConnection(modelConString);
        int intRecsAffect = -1;
        int count = 0;
        string strSql = "";
        conObj.Open();
        //sqlTrans = conObj.BeginTransaction();
        for (int i = 0; i < arr_emailInsert.Count; i++)
        {
            SqlCommand cmdObj = (SqlCommand)arr_emailInsert[i];
            strSql = cmdObj.CommandText;


            cmdObj.Connection = conObj;
            //cmdObj.Transaction = sqlTrans;
            count = i;
            intRecsAffect = cmdObj.ExecuteNonQuery();
            //LogWriter.WriteLog("Record affected : " + intRecsAffect.ToString());Commented by srivatsan on July 9 2009
        }
        if (intRecsAffect == -1)
        {

            lblMessage.Text = ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "E-mail Insert not successful. " + ErrorMessage, true);
            status = false;
            HDD = null;
            conObj.Close();
        }

        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : InsertEmailRecord: " + ex.Message);
        }
        finally
        {
            //SR = null;
            

        }

        return status;
    }
    private void GetUsers(DataTable Dt_Users, string subject)
    {
        if (Dt_Users.Rows.Count > 0)
        {
            for (int i = 0; i < Dt_Users.Rows.Count; i++)
            {
                if (Dt_Users.Rows[i]["assign_type"].ToString() == "usr")
                {
                    InsertEmailRecord(Dt_Users.Rows[i]["assign_type_id"].ToString(), subject);

                }
                if (Dt_Users.Rows[i]["assign_type"].ToString() == "role")
                {
                    DataTable dt = HDD.GetDataTable("SELECT * from sy_usr_rol where role_id='" + Dt_Users.Rows[i]["assign_type_id"].ToString() + "'");
                    if (dt != null & dt.Rows.Count > 0)
                    {
                        for (int j = 0; j < dt.Rows.Count; j++)
                        {
                            InsertEmailRecord(dt.Rows[j]["user_id"].ToString(), subject);
                        }
                    }
                }
                if (Dt_Users.Rows[i]["assign_type"].ToString() == "bu")
                {
                    DataTable dt = HDD.GetDataTable("select a.af_row_id from sy_usr a,sy_bu b where a.bu_id=b.bu_id and b.af_row_id='" + Dt_Users.Rows[i]["assign_type_id"].ToString() + "'");
                    if (dt != null & dt.Rows.Count > 0)
                    {
                        for (int j = 0; j < dt.Rows.Count; j++)
                        {
                            InsertEmailRecord(dt.Rows[j]["af_row_id"].ToString(), subject);
                        }
                    }
                }
            }
        }
    }
    private void InsertEmailRecord(string user, string subject)
    {
        ScreenReader SR = new ScreenReader();
        //string Template = File.ReadAllText("C:\\inetpub\\wwwroot\\MaxBlox\\E-mailTemplates\\E-mail Template.html");
try
        {
        string filepath = HttpContext.Current.Request.PhysicalApplicationPath;
        filepath += "/E-mailTemplates/E-mail Template.htm";
        string Template = File.ReadAllText(filepath);



        DataTable dt_user = HDD.GetDataTable("select * from sy_usr where af_row_id='" + user + "'");
        string name = dt_user.Rows[0]["first_name"].ToString() + dt_user.Rows[0]["last_name"].ToString();
        
        SqlCommand sqlcmd;
        string sql = "";
        Template = string.Format(Template, name, p_task_config_subject.Text, p_task_config_status.SelectedItem.Text, p_task_config_priority.SelectedItem.Text, p_task_config_start_date.Text, p_task_config_finish_date.Text);
        string toaddress = dt_user.Rows[0]["email_id"].ToString();

        string af_row_id = SR.getHashKey();
        string fromaddress = HDD.GetColumnValue("select email_id from sy_usr where af_row_id='" + p_task_config_owner_id.Value + "'");
        sql = "insert into [email_queue] ([from_address],[to_address],[isHtml],[bcc_address],[subject],[Content],[Priority],[Delivery],[af_row_id],[created_by],[created_at],[modified_at],[modified_by],[owner_id]) values ('" + fromaddress + "','" + toaddress + "',1,'','" + subject + "','" + Template + "',0,'" + DateTime.Now.ToUniversalTime() + "','" + af_row_id + "','" + Session["user_afrowid"].ToString() + "','" + DateTime.Now.ToUniversalTime() + "','','','" + Session["user_afrowid"].ToString() + "')";
        sqlcmd = new SqlCommand(sql);
        arr_emailInsert.Add(sqlcmd);
    }
    catch (Exception ex)
    {
        LogWriter.WriteLog("Error : InsertEmailRecord: " + ex.Message);
    }
    finally
    {
        SR = null;

    }

    }
    private void DefaultColumnUpdate()
    {
        string strPageId = "";
        string[,] pagearr = pagearr = new string[,] 
            {
                {"Task", "p_task_config"},
                {"Assign", "p_assign_task"},
                //{"AlertStatus", "p_alert_status"},
                {"ObjectRec","p_task_object_ref"}
            };

        for (int j = 0; j <= pagearr.GetUpperBound(0); j++)
        {
            strPageId = pagearr[j, 1].ToString();
            foreach (DataRow dr in dseInputInfo.Tables[strPageId].Rows)
            {
                if (IsEdit)
                {
                if (dseInputInfo.Tables[strPageId].Columns.Contains("modified_date"))
                {
                    dr["modified_date"] = DateTime.Now.ToUniversalTime().ToString();
                }
                else if (dseInputInfo.Tables[strPageId].Columns.Contains("modified_at"))
                {
                    dr["modified_at"] = DateTime.Now.ToUniversalTime().ToString();
                }

                
                }
                else
                {
                    if (dseInputInfo.Tables[strPageId].Columns.Contains("created_date"))
                    {
                        dr["created_date"] = DateTime.Now.ToUniversalTime().ToString();
                    }
                    else if (dseInputInfo.Tables[strPageId].Columns.Contains("created_at"))
                    {
                        dr["created_at"] = DateTime.Now.ToUniversalTime().ToString();
                    }
                }

                if (dseInputInfo.Tables[strPageId].Columns.Contains("modified_by"))
                {
                    dr["modified_by"] = HttpContext.Current.Session["user_afrowid"].ToString();
                }

                if (IsEdit)
                {
                }
                else
                {
                    if (dseInputInfo.Tables[strPageId].Columns.Contains("created_by"))
                    {
                        dr["created_by"] = HttpContext.Current.Session["user_afrowid"].ToString();
                    }

                }

            }
        }
    }
    private Label getMessageLabel()
    {
        DynamicDisplayI ddi = null;
        Label lblRet = new Label();
        try
        {
            
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error :getMessageLabel " + e.Message);
        }
        finally { ddi = null; }
        return lblRet;
    }
    private bool validateOwnerid(ref Label lblMessage)
    {
        bool status = false;
        HDD = new HDDatabase();
        BindControl BC = new BindControl();
        DataSet dsBind = new DataSet();
        string sql = BC.GetBindSql("f496930dfe0b690f");
        dsBind = HDD.GetDataset(sql);
        if (dsBind != null)
        {
            if (dsBind.Tables.Count > 0)
            {
                if (dsBind.Tables[0].Rows.Count > 0)
                {

                    DataRow[] drrbind = dsBind.Tables[0].Select("fld =  '" + txt_owner_id.Text + "'");

                    if (drrbind.Length > 0)
                    {
                        p_task_config_owner_id.Value = drrbind[0]["val"].ToString();
                        status = true;
                    }

                }
                else
                {
                    p_task_config_owner_id.Value = "";
                    status = true;
                }
            }
        }
        if (status != true)
        {

            lblMessage.Text = ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp; Error: Invalid data for Owner :", true);

        }
        return status;

    }
    
    public void LoadDD(DropDownList assign_type, DropDownList assign_to)
    {
        BindControl BC = new BindControl();
        HDDatabase Hdd = new HDDatabase();
        DataTable dt = new DataTable();
        string sql = "";

        if (assign_type.SelectedValue.ToLower() == "usr")
            sql = BC.GetBindSql("92919057f8346696");
        else if (assign_type.SelectedValue.ToLower() == "role")
            sql = BC.GetBindSql("e0b5144eca48948a");
        else if (assign_type.SelectedValue.ToLower() == "bu")
            sql = BC.GetBindSql("dc80380fe3a93228");
        dt.Clear();
        if (sql.Trim() != "")
            dt = Hdd.GetDataTable(sql);
        assign_to.Items.Clear();
        assign_to.DataSource = dt;
        assign_to.DataTextField = "Fld";
        assign_to.DataValueField = "Val";
        assign_to.DataBind();
        assign_to.Items.Insert(0, new ListItem("--Select--", "0"));
        BC = null;
        Hdd = null;

    }

    protected void bt_single_Click(object sender, EventArgs e)
    {

    }
    protected void p_taskassign_multiple_SelectedIndexChanged(object sender, EventArgs e)
    {
        LoadList(LstLeft);
        if (LstRight.Items.Count > 0)
            LstRight.Items.Clear();
        div_multiple.Style.Add("display", "block");
        AssignToLable.Style.Add("display", "block");
        //if (p_taskassign_assign_to.Value == "0")
        //{
        //    assign_to.Enabled = false;
        //    imgsearch1.Visible = false;

        //}
        if (p_taskassign_multiple.SelectedIndex == 0)
        {
            assign_to.Enabled = true;
            imgsearch1.Visible = true;

        }
        else
        {
            assign_to.Text = "";
            p_taskassign_assign_to.Value = "0";
            assign_to.Enabled = false;
            imgsearch1.Visible = false;

        }


    }
    protected void object_ref_SelectedIndexChanged(object sender, EventArgs e)
    {

        LoadObjGrid(object_ref.SelectedValue);
        txt_obj_rec.Text = "";

    }
    void LoadObjGrid(string ObjectID)
    {
        HDDatabase HDD = new HDDatabase();
        DataView dv;
        try
        {
        DataSet dsFunc = new DataSet();
        string table_name = HDD.GetColumnValue("Select object_table from sy_obj where af_row_id='" + ObjectID + "'");
        string strPagesetRowId = HDD.GetColumnValue("select pageset_id from sy_pgs_mem where object_id=(select object_id from sy_obj where af_row_id = '" + ObjectID + "');");
        //string strPagesetRowId = HDD.GetColumnValue("select pageset_id from sy_pgs where af_row_id = (select pageset_id from sy_pgs_mem where object_id=(select object_id from sy_obj where af_row_id = '" + ObjectID + "'));");
        //dsFunc = HDD.GetDataset("Select * from " + table_name); // Commented by 'Imran Gani' on 28-Feb-2014, for searchable fields
        dsFunc = HDD.GetDataset("select * from sy_pgs_srh where pageset_id = '" + strPagesetRowId + "' order by search_seq;");
        if (dsFunc != null)
        {
            if (dsFunc.Tables.Count != 0 && dsFunc.Tables[0].Rows.Count != 0)
            {

                string ColNam = "";
                #region Old code commented by 'Imran Gani' on 28-Feb-2014, for searchable fields
                //foreach (DataColumn dc_Col in dsFunc.Tables[0].Columns)
                //{
                //    if (dc_Col.ColumnName != "af_row_id" && dc_Col.ColumnName != "owner_id" && dc_Col.ColumnName != "created_by" && dc_Col.ColumnName != "modified_by" && dc_Col.ColumnName != "modified_at" && dc_Col.ColumnName != "created_at")
                //    {
                //        ColNam += dc_Col.ColumnName + ",";
                //    }
                //}
                foreach (DataRow dr in dsFunc.Tables[0].Rows) // Added by 'Imran Gani' on 28-Feb-2014, to display multiple search fields
                {
                    ColNam += dr["search_attrib_id"].ToString() + ",";
                }
                #endregion
                //ColNam += dsFunc.Tables[0].Rows[0]["search_attrib_id"].ToString() + ","; // Added by 'Imran Gani' on 28-Feb-2014, for search field

                ColNam = ColNam.TrimEnd(',');
                string textboxid = txt_obj_rec.ID;
                string hiddenfieldid = p_task_config_object_record_ref.ID;
                imgsearch.Attributes.Add("onclick", "javascript:openlookupwindowForMasterDetail('" + hiddenfieldid + "','" + textboxid + "','','','" + strPagesetRowId + "','" + ColNam + "','" + table_name + "');");
                if (Request.QueryString["ID"] != "")
                {
                    DataTable dt = HDD.GetDataTable("select af_row_id as Val," + ColNam + " from " + table_name + " where af_row_id='" + Request.QueryString["ID"] + "'");
                    if (dt.Rows.Count > 0)
                    {
                        txt_obj_rec.Text = dt.Rows[0][1].ToString();
                    }
                }

            }

        }
    }
    catch (Exception ex)
    {
        LogWriter.WriteLog("Error : Loading Object Grid : " + ex.Message);
    }
    finally
    {
        HDD = null;

    }


    }

    protected void BtnRight_Click(object sender, EventArgs e)
    {
        if (LstLeft.Items.Count > 0)
        {

            for (int i = LstLeft.Items.Count - 1; i >= 0; i--)
            {
                if (LstLeft.Items[i].Selected == true)
                {

                    LstRight.Items.Add(new ListItem(LstLeft.Items[i].Text, LstLeft.Items[i].Value));
                    ListItem li = LstLeft.Items[i];
                    LstLeft.Items.Remove(li);
                }
            }
        }
    }

    bool IsItemExists(ListBox Lst, string Value)
    {
        bool exist = false;
        for (int i = 0; i < Lst.Items.Count; i++)
        {
            if (Lst.Items[i].Value == Value)
            {
                exist = true;
            }

        }
        return exist;
    }
    protected void BtnRightAll_Click(object sender, EventArgs e)
    {
        if (LstLeft.Items.Count > 0)
        {

            for (int i = LstLeft.Items.Count - 1; i >= 0; i--)
            {
                LstRight.Items.Add(new ListItem(LstLeft.Items[i].Text, LstLeft.Items[i].Value));
                ListItem li = LstLeft.Items[i];
                LstLeft.Items.Remove(li);

            }
        }

    }
    protected void BtnLeftAll_Click(object sender, EventArgs e)
    {
        if (LstRight.Items.Count > 0)
        {

            for (int i = LstRight.Items.Count - 1; i >= 0; i--)
            {
                LstLeft.Items.Add(new ListItem(LstRight.Items[i].Text, LstRight.Items[i].Value));
                ListItem li = LstRight.Items[i];
                LstRight.Items.Remove(li);
            }
        }

    }

    protected void BtnLeft_Click(object sender, EventArgs e)
    {
        if (LstRight.Items.Count > 0)
        {

            for (int i = LstRight.Items.Count - 1; i >= 0; i--)
            {
                if (LstRight.Items[i].Selected == true)
                {

                    LstLeft.Items.Add(new ListItem(LstRight.Items[i].Text, LstRight.Items[i].Value));
                    ListItem li = LstRight.Items[i];
                    LstRight.Items.Remove(li);
                }
            }
        }

    }
    protected void bt_Cancel_Click(object sender, EventArgs e)
    {
        try
        {
            string strPageUrl = Request.Url.ToString();
            Response.Redirect(strPageUrl);
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : TaskConfig : btnReset_Click() : " + ex.Message);
        }
    }
    protected void assign_to_TextChanged(object sender, EventArgs e)
    {
        if (assign_to.Text == "")
            p_taskassign_assign_to.Value = "0";
        if (p_taskassign_assign_to.Value == "0")
        {
            div_multiple.Style.Add("display", "block");
            AssignToLable.Style.Add("display", "block");
        }

    }
    protected void p_task_config_status_SelectedIndexChanged(object sender, EventArgs e)
    {
        StatusChange = true;

    }
    protected void bt_saveNext_Click(object sender, EventArgs e)
    {
        
        HDDatabase HDD = new HDDatabase();
        bool status = true;
        
        DynamicDisplayI ddi = new DynamicDisplayI();
        Localization loc = new Localization();
        string start_dt = "";
        string end_dt = "";
        string strUTCoffset = "";
        strUTCoffset = ddi.getUserSetting("sy_usr", "time_zone", "sy_timezone", "utc_offset", "timezone_id");
        //start_dt = GetUserTime(p_task_config_start_date.Text, strUTCoffset,true); // Commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
        //end_dt = GetUserTime(p_task_config_finish_date.Text, strUTCoffset,true); // Commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
        start_dt = loc.getDateTime4TimeZone(p_task_config_start_date.Text, strUTCoffset, true, false);
        end_dt = loc.getDateTime4TimeZone(p_task_config_finish_date.Text, strUTCoffset, true, false);
        if (start_dt != "" && end_dt != "")
        {
            if (!DateValidation(start_dt, end_dt, ref lblMessage))
                return;
            status = GetTaskData(ref lblMessage);
            if (status == true)
            {
                if (SaveTask(ref lblMessage))
                {

                    lblMessage.Text = ErrMessage("&nbsp;<img src='Images/info.gif' border='0'>&nbsp;Data Inserted Successfully", false);
                    ViewState["dseTempInputInfo"] = null;
                    string strMenuRowId = HDD.GetColumnValue("select af_row_id from sy_mnu where pageset_id='aa922f981c2500e0';"); // pageset_id='task_config'
                    Response.Redirect("TaskConfig.aspx?pgs_id=aa922f981c2500e0&mn=" + strMenuRowId);
                }
                else
                {
                    lblMessage.Text = ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Data Insert not successful. " + ErrorMessage, true);
                }
            }
            else
            {
                return;
            }
        }
        else
        {
            lblMessage.Text = ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Invalid date  " + ErrorMessage, true);
            return;
        }

    }
    #region Old Code commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
    //private string GetUserTime(string input, string strUTCoffset, bool isForStoring)
    //{
    //    string sValue = "";
    //    string timeZoneOffest = strUTCoffset;
    //    DynamicDisplayI ddi = new DynamicDisplayI();
    //    Localization loc = new Localization();
    //    string sDateTimeFormatString = loc.getDateFormat() + " hh:mm tt";
    //    DateTime dt = new DateTime();
    //    try
    //    {
    //        string sHours = "";
    //        string sMinutes = "";
    //        bool isSystem = false;
    //        // if (input == "") return input;
    //        if (timeZoneOffest != "")
    //        {
    //            if (isForStoring)
    //            {
    //                if (timeZoneOffest.StartsWith("-"))
    //                    timeZoneOffest = "+" + timeZoneOffest.Substring(1);
    //                else if (timeZoneOffest.StartsWith("+"))
    //                    timeZoneOffest = "-" + timeZoneOffest.Substring(1);
    //                else if (timeZoneOffest.Trim() != "0")
    //                    timeZoneOffest = "+" + timeZoneOffest;
    //            }
    //            if (timeZoneOffest.IndexOf('.') != -1)
    //            {
    //                sHours = timeZoneOffest.Substring(1, timeZoneOffest.IndexOf('.') - 1);
    //                sMinutes = timeZoneOffest.Substring(timeZoneOffest.IndexOf('.') + 1, timeZoneOffest.Length - timeZoneOffest.IndexOf('.') - 1);
    //            }
    //            else
    //                sHours = timeZoneOffest.Substring(1, timeZoneOffest.Length - 1);

    //            if (timeZoneOffest.StartsWith("-"))
    //            {
    //                sHours = "-" + sHours;
    //                if (sMinutes != "")
    //                    sMinutes = "-" + sMinutes;
    //            }
    //        }
    //        if (sHours == "") sHours = "0";
    //        if (isForStoring)
    //            dt = DateTime.Parse(input, loc.getUserCulture());
    //        else
    //            dt = DateTime.Parse(input); //DateTime.Parse(input);//sanal on Sept 04, 2008
    //        dt = dt.AddHours(Convert.ToDouble(sHours));
    //        if (sMinutes != "")
    //            dt = dt.AddMinutes(Convert.ToDouble(sMinutes));
    //        if (isForStoring)
    //            sValue = dt.ToUniversalTime().ToString();
    //        else
    //            sValue = isSystem== true? dt.ToString(sDateTimeFormatString) : dt.ToLocalTime().ToString(sDateTimeFormatString); //dt.ToString(sDateTimeFormatStrin
    //        //sValue = dt.ToUniversalTime().ToString(CultureInfo.InvariantCulture);
    //        //else
    //        // sValue = isSystem == true ? dt.ToString(sDateTimeFormatString) : dt.ToLocalTime().ToString(sDateTimeFormatString);
    //    }
    //    catch (Exception ex)
    //    {
    //        LogWriter.WriteLog("getInvariantDateTime : Error : " + ex.Message);
    //        sValue = "";
    //    }
    //    return sValue;
    //}
    #endregion

    /// <summary>
    /// To validate Start date to be less than End date.
    /// </summary>
    /// <param name="start_dt">Start date</param>
    /// <param name="end_dt">End date</param>
    /// <param name="lblMessage">Lable control to display message.</param>
    /// <returns>Boolean (True / False)</returns>
    private bool DateValidation(string start_dt, string end_dt, ref Label lblMessage)
    {
        try
        {
            DateTime StartDate = Convert.ToDateTime(start_dt);
            DateTime EndDate = Convert.ToDateTime(end_dt);
            if (StartDate > EndDate)
            {
                lblMessage.Text = wrapItAsMessage("<img src=\"Images/info.gif\" alt=\"\"></img>&nbsp;End date should be greater than Start date.", true);
                return false;
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("DateValidation : Error : " + ex.Message);
        }
        return true;
    }
}
